package com.shujia.wyh.jinjie;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/*
    1、redis-hbase 索引实现，优化

    2、flume
 */
public class PhoenixJDBCDemo {
    public static void main(String[] args) throws Exception{
        //1、加载驱动
        String driver = "org.apache.phoenix.jdbc.PhoenixDriver";
        String url = "jdbc:phoenix:master,node1,node2:2181"; //只需要在最后一个节点后面写上zookeeper端口号
        Class.forName(driver);

        //2、创建数据库连接对象
        Connection conn = DriverManager.getConnection(url);

        //3、获取数据库操作对象
        PreparedStatement preparedStatement = conn.prepareStatement("select /*+ INDEX(DIANXIN DIANXIN_INDEX_COVER) */ * from DIANXIN where x=? and y=?");

        preparedStatement.setDouble(1,121.447);
        preparedStatement.setDouble(2,31.188);

        //执行sql语句
        ResultSet resultSet = preparedStatement.executeQuery();

        while (resultSet.next()){
            String phoneNum = resultSet.getString("mdn");
            String start_date = resultSet.getString("start_date");
            String end_date = resultSet.getString("end_date");
            String county = resultSet.getString("county");
            String x = resultSet.getString("x");
            String y = resultSet.getString("y");
            System.out.println(phoneNum+"\t"+start_date+"\t"+end_date+"\t"+county+"\t"+x+"\t"+y);
        }

        //释放资源
        preparedStatement.close();
        conn.close();

    }
}
